#include "myStack.h"
#include <malloc.h>
/** Initialize your data structure here. */
MyStack* myStackCreate(int maxSize) {
    MyStack *ms = malloc(sizeof(MyStack));
    ms->stack = malloc(sizeof(TDSTYPE)*maxSize);
    ms->top = 0;
    return ms;
}

/** Push element x onto stack. */
void myStackPush(MyStack* obj, TDSTYPE x) {
    obj->stack[obj->top++] = x;
}

/** Removes the element on top of the stack and returns that element. */
TDSTYPE myStackPop(MyStack *obj) {
    return obj->stack[--obj->top];
}

/** Get the top element. */
TDSTYPE myStackTop(MyStack* obj) {
    return obj->stack[obj->top - 1];
}

/** Returns whether the stack is empty. */
int myStackEmpty(MyStack* obj) {
    return obj->top == 0;
}

void myStackFree(MyStack* obj) {
    free(obj->stack);
    free(obj);
}


//**************TestCode******************



#include <stdio.h>


int main(void) {
    MyStack *ms = myStackCreate(10);
    printf("EmptyStack:%d\n", myStackEmpty(ms));
    int i;
    for(i=0; i<10; i++)
        myStackPush(ms, i+65);
    printf("%c\n", myStackTop(ms));
    for(i=0; i<10; i++)
        printf("%c\n", myStackPop(ms));
    myStackFree(ms);
    return 0;
} 

/******************************************/
